package dolf.objects;

import java.awt.Graphics2D;
import java.awt.Color;
import dolf.game.BloodManager;


public class BloodObject extends WorldObject implements java.io.Serializable{
	
	private static final long serialVersionUID = 1L;
	private Point[] positions;
	private Vector[] vec;
	private Color[] col;
	private int amount;
	private int lifeTime;
	public BloodObject(int _amount, Point pos){
		super(false);
		//this.setPosition(new Point(pos.getX(), pos.getY()));
		positions = new Point[_amount];
		vec = new Vector[_amount];
		col = new Color[_amount];
		this.amount = _amount;
		this.lifeTime = 40;
		for(int i = 0; i<_amount;i++){
			positions[i] = new Point(pos.getX(), pos.getY());
			double rnd = (Math.floor((Math.random() * 360))-180)*Math.PI/180;
			double rnd2 = Math.floor((Math.random() * 10)+1)/10;
			vec[i] = new Vector(Math.cos(rnd)*rnd2,Math.sin(rnd)*rnd2);
			int c = 128 + (int) (Math.random() * 128.0);
			col[i] = new Color(c,(int) (Math.random()*32),(int) (Math.random()*32));
		}
		
	}
	public boolean isMoving(){
		return false;
	}
	public void paint(Graphics2D g){
		Color tmp = g.getColor();
		this.lifeTime--;
		for(int i = 0;i<this.amount; i++){
					
			g.setColor(col[i]);
			
			g.drawOval(this.positions[i].getIntX(), this.positions[i].getIntY(), 1, 1);
			this.positions[i] = this.positions[i].add(this.vec[i]);
		}
		if(this.lifeTime <= 0){
			BloodManager.getInstance().removeBlood(this);
			return;
		}
		g.setColor(tmp);
		
	}
	public Point[] getPositions(){
		return this.positions;
	}
	public Color[] getColor(){
		return col;
	}
	

}
